package cn.lzj.ymcc.web.controller;

import cn.lzj.ymcc.doc.CourseDoc;
import cn.lzj.ymcc.dto.CourseSearchESParamDto;
import cn.lzj.ymcc.repository.CourseElasticsearchRepository;
import cn.lzj.ymcc.result.JSONResult;
import cn.lzj.ymcc.result.PageList;
import cn.lzj.ymcc.service.ICourseESService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseESController {
    @Autowired
    private ICourseESService courseESService;


    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public JSONResult save(@RequestBody  CourseDoc doc){

        courseESService.save(doc);

        return JSONResult.success();
    }
    @RequestMapping(value = "/offLineCourse/{id}",method = RequestMethod.DELETE)
    public JSONResult offLineCourse(@PathVariable Long id){

       courseESService.offLineCourse(id);

        return JSONResult.success();
    }
    @RequestMapping(value = "/search",method = RequestMethod.POST)
    public JSONResult search(@RequestBody CourseSearchESParamDto dto){
        PageList<CourseDoc> result=courseESService.search(dto);
        return JSONResult.success(result);
    }
}
